<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://csdnimg.cn/public/favicon.ico" rel="SHORTCUT ICON">
    <title>登录</title>
    <script src="./js/jquery-3.5.0.min.js"></script>
    <style>
        body {
            background-image: url("./imags/background.jpg");
            background-size: 100%;
            background-repeat: no-repeat;
        }

        .content {
            width: 500px;
            margin-left: auto;
            margin-right: auto;
        }

        .content>.avatar {
            border-radius: 50%;
            height: 100px;
            width: 100px;
            margin-left: auto;
            margin-right: auto;
            margin-top: 30px;
            margin-bottom: 60px;
            background-image: url("./imags/avatar.jpg");
            background-size: 100%;
        }

        .content>.loginOrRegisterBox {
            height: 340px;
            width: 500px;
            border-radius: 10px;
            background-color: rgba(255, 255, 255, 0.3)
        }

        .content>.loginOrRegisterBox>.witch {
            height: 40px;
            width: 80%;
            margin-left: auto;
            margin-right: auto;
            padding-top: 30px;
            list-style: none;
        }

        .content>.loginOrRegisterBox>.witch>#loginButton,
        .content>.loginOrRegisterBox>.witch>#registerButton {
            width: 200px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            color: #fff;
        }

        .content>.loginOrRegisterBox>.witch>#loginButton {
            border-bottom: 2px solid #fff;
            float: left;
            margin-left: -20px;
        }

        .content>.loginOrRegisterBox>.witch>#registerButton {
            float: right;
            margin-right: 20px;
        }

        .content>.loginOrRegisterBox>#form>form>input {
            width: 97.5%;
            height: 40px;
            margin-top: 15px;
            line-height: 20px;
            padding-left: 10px;
            border-radius: 5px;
            border-width: 0;
            background-color: rgba(255, 255, 255, 0.3);
        }

        .content>.loginOrRegisterBox>#form>form>input[type='submit'] {
            background-color: aqua;
            width: 100%;
            color: white;
        }

        .content>.loginOrRegisterBox>#form>form {
            margin-left: auto;
            margin-right: auto;
            width: 80%;
            height: 80%;
        }
        .content>.loginOrRegisterBox>#form>form>div {
            margin-top: 20px;
            height: 40px;
            width: 100%;
        }
        .content>.loginOrRegisterBox>#form>form>div>input,
        .content>.loginOrRegisterBox>#form>form>div>p {
            float: left;
        }
        .content>.loginOrRegisterBox>#form>form>div>a {
            float: right;
            margin-top: 1px;
            color: white;
            text-decoration: none;
        }
        .content>.loginOrRegisterBox>#form>form>div>p {
            margin-top: 1.5px;
            color: white;
        }
        .content>.loginOrRegisterBox>#form>form>div>input {
            height: 20px;
            width: 20px;
        }
        .content>.loginOrRegisterBox>#form>form>div>input::after {
            background-color: rgba(255, 255, 255, 1);
        }
        .content>.loginOrRegisterBox>#form>form>div>a:visited {
            color: white;
        }
        #register {
            display: none;
        }
        #create{
            font-size: 8px;
            margin-top: 10px;
            text-align: center;
            color: #888888;
        }
    </style>
</head>

<body>
    <div class="content">
        <div class="avatar"></div>
        <div class="loginOrRegisterBox">
            <ul class="witch">
                <li id="loginButton">登录</li>
                <li id="registerButton">注册</li>
            </ul>
            <div id="form">
                <form action="" id="login">
                    <input type="text" placeholder="用户名" name="username">
                    <input type="password" placeholder="密码" name="password">
                    <div>
                        <input type="checkbox" name="" id="">
                        <p>记住密码</p>
                        <a href="#">忘记密码？</a>
                    </div>
                  <a href="index2.html"> 登陆</a>
                </form>
                <form action="" id="register">
                    <input type="text" placeholder="用户名" name="username">
                    <input type="password" placeholder="密码" name="password">
                    <input type="password" placeholder="姓名">
                    <!-- <input type="password" placeholder="确认密码" name="confirmPassword"> -->
                    <!-- <input type="submit" value="立即注册"> -->
                    <button class="register_button">注册</button>
                </form>
                <!-- <div id="create">Created By &#64;Songothao</div> -->
            </div>
        </div>
    </div>
    
    <script src="./js/login.js"></script>
    <!-- <script>
        let login_button = document.querySelector('.login_button');
        let register_button = document.querySelector('.register_button');
        let inputs = document.getElementsByTagName('input');
                 console.log(inputs[3]);
                 
                 console.log(inputs[4]);
                          
                 console.log(inputs[5]);
                          
                 console.log(inputs[0]);
                          
                 console.log(inputs[1]); 
               
        login_button.addEventListener('click', ()=>{
                    var account = inputs[0].value.trim();
                    var password = inputs[1].value.trim();
                    if (account.length == 0 || password.length == 0) {
                        alert("用户名或密码为空");
                        return;
                    }
                    const myHeaders = new Headers()
                    myHeaders.append("Content-Type", "application/json")
                    let requestOptions = { // 里面不能有body
                        method: "GET",
                        headers: myHeaders,
                        redirect: "follow",
                    }
                    fetch(`http://123.60.44.50:3000/users/${account}`, requestOptions)
                        .then(response => response.json())
                        .then(data => {
                            if (data.id === account) {
                                if (data.password != password) {
                                    alert("密码错误")
                                    return;
                                } else {
                                    alert("登录成功")
                                    inputs[0].value = "";
                                    inputs[1].value = "";
                                    var url = 'home.html?data.name='+data.name;
                                    url = encodeURI(url)
                                    window.location.replace(url);
                                }
                            } else {
                                alert("用户名不存在")
                                throw new Error("用户名不存在")
                            }
                        })
                        .catch(err => console.log(err))
                })         


        register_button.addEventListener('click', ()=>{
                    for (var i = 3; i < 6; i++) {
                        if (inputs[i].value.trim().length == 0) {
                            alert("用户名或密码或姓名为空");
                            return;
                        }
                    }
                            
                    const myHeaders = new Headers()
                    myHeaders.append("Content-Type", "application/json")
                    let requestOptions = {
                        method: "POST",
                        headers: myHeaders,
                        redirect: "follow",
                    }
                    requestOptions.body = JSON.stringify({
                        id: inputs[3].value, password: inputs[4].value, name: inputs[5].value,tasks:[],    // 初始化一个空的待办清单
                    });  
                    fetch(`http://123.60.44.50:3000/users`, requestOptions) 
                        .then(response => response.json())
                        .then(data => {
                            alert("注册成功");
                            inputs[3].value = "";
                            inputs[4].value = "";
                            inputs[5].value = "";
                        })  
                    .catch(err => {
                        alert("账号已被注册");
                    }
                    ) 
                })
        

                
          </script> -->

</body>

</html>